package controllers;

import play.*;
import play.mvc.*;
import play.data.*;

import models.*;
import views.html.*;

import static play.libs.Json.toJson;

public class Application extends Controller {
  
    public static Result index() {
        return ok(index.render("ITRACT"));
    }
    
    public static Result showAllStops() {
        return ok(stops.render(Stop.findAll(), null));
    }
    
    public static Result showStopsByName(String stop_name) {
        return ok(stops.render(Stop.findByName(stop_name), stop_name));
    }
    
    public static Result showStopsByNameBindFromRequest() {
        DynamicForm form = form().bindFromRequest(); 
        String stop_name = form.get("stop_name");
        return redirect(
            routes.Application.showStopsByName(stop_name)
        );
    }

    public static Result showStop(String stop_id) {
        return ok(stop.render(Stop.findById(stop_id)));
    }
    
    public static Result json(String stop_name){
        return ok(toJson(Stop.findByName(stop_name)));
    }
    
    public static Result jsonAll(){
        return ok(toJson(Stop.findAll()));
    }
}